#create func map_key, which takes in keyvalue and nest_map
# the func first get the key from keyvalue
# then use the key to get the value from nest_map
# input: keyvalue: {4:to}
# input: nest map:  {2:{3:name, 2:friend, 1:teacher}, 4: {2:My, 1:Your, 3:Their}, 3:{1:am, 3:is, 2:are}, 1:{2:Bob, 3:Jack, 1:Lucy}}
# output: {2:My, 1:Your, 3:Their}
# input: keyvalue: {2:"I"}
# output: {3:'name', 2:'friend', 1:'teacher'}
# input: keyvalue: {3:"for"}
# output: {1:'am', 3:'is', 2:'are'}
# input: keyvalue: {1:"you"}
# output: {2:'Bob', 3:'Jack', 1:'Lucy'}
def map_key(keyvalue, nest_map):
  key = list(keyvalue.keys())[0]
  return nest_map[key]

#create func map_value
# input 1 is keyvalue
# another input is output of map_key
# the map_value will get the value from the input keyvalue
# then get the letter count of the value
# then use the letter count as key to get the value from the map_key
# input: keyvalue: {4:to}
# input: {2:My, 1:Your, 3:Their}
# output: "My"
# input: keyvalue: {2:"I"}
# input: {3:'name', 2:'friend', 1:'teacher'}
# output: "teacher"
# input: keyvalue: {3:"for"}
# input: {1:'am', 3:'is', 2:'are'}
# output: "is"
# input: keyvalue: {1:"you"}
# input: {2:'Bob', 3:'Jack', 1:'Lucy'}
# output: "Jack"
def map_value(keyvalue, map_key):
  value = list(keyvalue.values())[0]
  letter_count = len(value)
  return map_key[letter_count]

# create func：get_sentence
# input 1 is map
# input 2 is nest_map
# the func will interate the input map to get the keyvalues
# then call map_key with keyvalue and nest_map, to get the map_key_result
# then call map_value with keyvalue and map_key_result, to get the map_value_result
# then append the map_value_result to be a sentence
# input: [{4:"to"}, {2:"I"}, {3:"for"}, {1:"and"}]
# input: {2:{3:name, 2:friend, 1:teacher}, 4: {2:My, 1:Your, 3:Their}, 3:{1:am, 3:is, 2:are}, 1:{2:Bob, 3:Jack, 1:Lucy}}
# output: "My teacher is Jack"
def get_sentence(map, nest_map):
  sentence = ""
  for keyvalue in map:
    map_key_result = map_key(keyvalue, nest_map)
    map_value_result = map_value(keyvalue, map_key_result)
    sentence += map_value_result + " "
  print(sentence)
  return sentence.strip()